﻿
@inject IDbTemplateService mService
@model DbTemplateEntity
@{
    ViewData["Title"] = "数据常用模板 编辑";
    Layout = "../Shared/_Layout.cshtml";
}
@section links{

}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content text-center p-md">
                    <form id="dynamic-form" asp-action="Edit" method="post" class="form-horizontal" role="form">
                        <div asp-validation-summary="@ValidationSummary.All" class="text-danger"></div>
                        <input type="hidden" asp-for="TemplateId" />
                        <div class="form-group">
                            <label asp-for="ParentId" class="col-md-2 control-label text-right"> 上级</label>
                            <div class="col-md-10  text-left">
                                <div class="input-group m-b">
                                    <span class="input-group-addon">*</span>
                                    <select class="select2" asp-for="ParentId">
                                        <option value="">不限</option>
                                        @{
                                            var lst = mService.GetAll();
                                            if (lst != null && lst.Count > 0)
                                            {
                                                foreach (var item in lst)
                                                {

                                                    @Html.Raw(" <option value='" + item.TemplateId + "' " + (item.TemplateId == Model.ParentId ? "selected" : "") + ">" + item.TemplateName + "</option>")
                                                }
                                            }
                                        }
                                    </select>
                                </div>
                                <span asp-validation-for="ParentId" class="text-danger"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label asp-for="TemplateName" class="col-md-2 control-label text-right"> 模板名称</label>
                            <div class="col-md-10  text-left">
                                <div class="input-group m-b">
                                    <span class="input-group-addon">*</span>
                                    <input asp-for="TemplateName" class="form-control" validate="{required:true ,maxlength:50   }" />
                                </div>
                                <span asp-validation-for="TemplateName" class="text-danger"></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label asp-for="Remark" class="col-md-2 control-label text-right">描述</label>
                            <div class="col-md-10  text-left">

                                <textarea asp-for="Remark" class="form-control" validate="{required:false ,maxlength:200   }" rows="5"></textarea>
           
                                <span asp-validation-for="Remark" class="text-danger"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label asp-for="DataTContent" class="col-md-2 control-label text-right">模板</label>
                            <div class="col-md-10  text-left">

                                <textarea asp-for="DataTContent" class="form-control codemirror" validate="{required:false   }" rows="10"></textarea>
                                <span asp-validation-for="DataTContent" class="text-danger"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <a class="btn btn-white" asp-action="index">返  回</a>

                                <button class="btn btn-primary" type="submit">保存</button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

@section scripts{

    <script type="text/javascript">
    $(function () {
        $(document).ready(function () {
            $(".form-horizontal").CustomForm({
                isValidate: true,
                isTable: false
            });
            var editor = CodeMirror.fromTextArea($("#DataTContent")[0], {
                mode: 'htmlmixed',     // HMTL混合模式

                indentUnit: 2,  // 缩进单位，默认2
                smartIndent: false,  // 是否智能缩进
                tabSize: 4,  // Tab缩进，默认4
                readOnly: false,  // 是否只读，默认false
                showCursorWhenSelecting: true,
                lineNumbers: true  // 是否显示行号

            });
            editor.setValue($("#DataTContent").val());
            $(".form-horizontal").submit(function () {
                if (!$(".form-horizontal").valid())
                {
                    return false;
                }
                $("#DataTContent").val(editor.getValue());
            });

	  });
    });
    </script>
}